package tw.com.jinwei.service;

import java.util.List;

import org.apache.log4j.Logger;

import tw.com.jinwei.db.FunctionDAO;
import tw.com.jinwei.db.User;
import tw.com.jinwei.db.UserDAO;
import tw.com.jinwei.utils.LogHelper;

public class Authorize {

	private Logger log = LogHelper.getLog(getClass());
	private FunctionDAO functionDao;
	private UserDAO userDao;

	public FunctionDAO getFunctionDao() {
		return functionDao;
	}

	public void setFunctionDao(FunctionDAO functionDao) {
		this.functionDao = functionDao;
	}

	public UserDAO getUserDAO() {
		return userDao;
	}

	public void setUserDao(UserDAO userDao) {
		this.userDao = userDao;
	}

	public void saveNewUser(User user) {
		userDao.save(user);
	}

	public List findParentFunctions() {
		return functionDao.findParentFunctions();
	}

	public List queryAllUser() {
		return userDao.findAll();
	}

	public List queryUserByName(String name) {
		return userDao.findByName(name);
	}

	public User queryUser(String name, String password) {
		User user = new User();
		user.setName(name);
		user.setPassword(password);
		return (User) userDao.findByExample(user).get(0);
	}

	public void updateUser(User user) {
		userDao.attachDirty(user);
	}
	
	public void deleteUser(User user) {
		userDao.delete(user);
	}
}
